package ${package.ServiceImpl};

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.toolkit.SqlHelper;
import com.tele.common.bean.Query;
import com.tele.common.service.BasicBeanService;
import com.tele.common.utils.BeanUtils;
import com.tele.common.vo.Result;
import ${package.Entity}.${entity};
import ${cfg.EntityVo}.${table.entityName}VO;
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author ${author}
 * @version 1.0
 * @date ${.now}
 * @Description ${table.comment}服务层实现类
 */
@Service
public class ${table.serviceImplName} extends BasicBeanService<${table.entityName}, ${table.mapperName}> implements ${table.serviceName} {

    /**
     * 分页获取${table.comment}列表
     *
     * @param query 查询参数
     * @return {@link Result}
     */
    @Override
    public Result<Page<${table.entityName}VO>> findPage(Query<${table.entityName}VO> query) {
        Page page = super.findAllByQuery(query);
        List<${table.entityName}> records = page.getRecords();

        List<${table.entityName}VO> collect = records.stream().map(map -> {
            ${table.entityName}VO ${table.entityPath}VO = new ${table.entityName}VO();
            BeanUtils.copyProperties(map, ${table.entityPath}VO);
            return ${table.entityPath}VO;
            }).collect(Collectors.toList());
        page.setRecords(collect);
        return Result.ok(page);
    }

    /**
     * 新增${table.comment}信息
     *
     * @param ${table.entityPath}VO ${table.comment}
     * @return {@link Result<String>}
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<String> add${table.entityName}(${table.entityName}VO ${table.entityPath}VO) {
        ${table.entityName} ${table.entityPath} = new ${table.entityName}();
        BeanUtils.copyProperties(${table.entityPath}VO, ${table.entityPath});
        return SqlHelper.retBool(baseMapper.insert(${table.entityPath})) ? Result.ok("插入成功！", null) : Result.fail("插入失败！", null);
    }

    /**
     * 修改${table.comment}信息
     *
     * @param ${table.entityPath}VO ${table.comment}
     * @return {@link Result<String>}
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<String> update${table.entityName}(${table.entityName}VO ${table.entityPath}VO) {
        ${table.entityName} ${table.entityPath} = new ${table.entityName}();
        BeanUtils.copyProperties(${table.entityPath}VO, ${table.entityPath});
        return SqlHelper.retBool(baseMapper.updateById(${table.entityPath})) ? Result.ok("修改成功！", null) : Result.fail("请勿重复修改，或没有找到该条数据！", null);
    }

    /**
     * 删除${table.comment}信息
     *
     * @param ids ${table.comment}Ids
     * @return {@link Result<String>}
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result<String> deleteByIds(List<String> ids) {
        baseMapper.deleteBatchIds(ids);
        return Result.ok("删除成功！");
    }
}